//
//  BinInfoCell.swift
//  ams
//
//  Created by yangyuan on 2017/6/23.
//  Copyright © 2017年 coterjiesen. All rights reserved.
//

import UIKit

class LableView: UIView {
    var titleLable: UILabel = {
        let lable = UILabel()
        lable.font = v2Font(17)
        lable.textColor = .white
        return lable
    }()
    var valueLable: UILabel = {
        let lable = UILabel()
        lable.font = v2Font(15)
        lable.textColor = .white
        lable.text = "0"
        return lable
    }()
    let horizontalLine = UIView()        //分隔线
    
    override init(frame: CGRect) {
        super.init(frame: frame	)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI(){
        self.layer.cornerRadius = 20;
        self.layer.borderWidth = 1
        self.layer.borderColor = UIColor(white: 1, alpha: 0.5).cgColor;
        self.addSubview(horizontalLine)
        self.addSubview(titleLable)
        self.addSubview(valueLable)
        horizontalLine.backgroundColor = .white
        self.snp.makeConstraints { (make) in
            make.left.top.right.bottom.equalTo(self)
        }
        titleLable.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(4)
        }
        horizontalLine.snp.makeConstraints { (make) -> Void in
            make.height.equalTo(2)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.centerY.equalTo(self).offset(1)
        }
        valueLable.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(self.horizontalLine.snp.bottom).offset(4)
        }
    }
}

class BinInfoViewCell: UITableViewCell {
    
    let inBinView = LableView()
    let outBinView = LableView()
    let scrapView = LableView()
    let repairView = LableView()
    let inNetView = LableView()
    let totalView = LableView()
    
    required init?(coder aDecoder : NSCoder){
        super.init(coder: aDecoder)
    }
    required override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    func setupUI(){
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.backgroundColor = UIColor.clear
        self.contentView.backgroundColor = UIColor.clear
        
        inBinView.titleLable.text = "入库数量"
        outBinView.titleLable.text = "出库数量"
        scrapView.titleLable.text = "报废数量"
        repairView.titleLable.text = "返修数量"
        inNetView.titleLable.text = "入网数量"
        totalView.titleLable.text = "库存总量"
        self.contentView.addSubview(inBinView)
        self.contentView.addSubview(outBinView)
        self.contentView.addSubview(scrapView)
        self.contentView.addSubview(repairView)
        self.contentView.addSubview(inNetView)
        self.contentView.addSubview(totalView)
        setupLayout()
    }
    func setupLayout(){
        self.contentView.snp.makeConstraints { (make) in
            make.top.left.right.bottom.equalTo(self)
        }
        inBinView.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView).offset(3)
            make.left.equalTo(self.contentView).offset(6)
            make.width.equalTo(self.contentView.frame.size.width / 3 - 16)
            make.height.equalTo(69)
        }
        outBinView.snp.makeConstraints { (make) in
            make.top.equalTo(self.inBinView)
            make.centerX.equalTo(self.contentView)
            make.width.equalTo(self.contentView.frame.size.width / 3 - 16)
            make.height.equalTo(69)
        }
        scrapView.snp.makeConstraints { (make) in
            make.top.equalTo(self.inBinView)
            make.right.equalTo(self.contentView).offset(-6)
            make.width.equalTo(self.contentView.frame.size.width / 3 - 16)
            make.height.equalTo(69)
        }
        repairView.snp.makeConstraints { (make) in
            make.top.equalTo(self.inBinView.snp.bottom).offset(4)
            make.left.equalTo(self.inBinView)
            make.width.equalTo(self.contentView.frame.size.width / 3 - 16)
            make.height.equalTo(69)
        }
        inNetView.snp.makeConstraints { (make) in
            make.top.equalTo(self.repairView)
            make.centerX.equalTo(self.contentView)
            make.width.equalTo(self.contentView.frame.size.width / 3 - 16)
            make.height.equalTo(69)
        }
        totalView.snp.makeConstraints { (make) in
            make.top.equalTo(self.repairView)
            make.left.equalTo(self.scrapView)
            make.width.equalTo(self.contentView.frame.size.width / 3 - 16)
            make.height.equalTo(69)
        }
    }
    func bind(){
        inBinView.valueLable.text = CuUser.sharedInstance.user?.putaway
        outBinView.valueLable.text = CuUser.sharedInstance.user?.putout
        scrapView.valueLable.text = CuUser.sharedInstance.user?.scrap
        repairView.valueLable.text =  CuUser.sharedInstance.user?.repair
        inNetView.valueLable.text = CuUser.sharedInstance.user?.netIn
        totalView.valueLable.text =  CuUser.sharedInstance.user?.putaway
        print("lodingdata")
    }
}
